var paginationTotal = 1;// 记录总数
$(function() {
//	initData(0); // 初始化分页<{$lang.data}>
	clear();

	// <{$lang.delete}>
	$("#right_confirm").dialog({
		autoOpen : false,
		modal : true,
		height : 'auto',
		show : "slide",
		buttons : {
			'<{$lang.ok}>' : function() {
				$('#message').text("");
				loading();
				$.ajax({ // 这里使用到Jquery的ajax<{$lang.method}>
					type : "POST",
					async : false,
					dataType : "json",
					url : "/product/product/update-status", // 请求的处理url
					data : {
						'product_id' : Uid,
						'product_status' : Ustatus
					},
					success : function(json) {
						closeLoading();
						if (json.ask == 1) {// <{$lang.operation}><{$lang.success}>

							$('#alert_msg p').html(json.msg);
							$('#alert_msg').dialog('open');
							loadData(paginationCurrentPage, paginationPageSize);
						} else {
							$('#alert_msg p').text("<{$lang.operation}><{$lang.fail}>");
							$('#alert_msg').dialog('open');
						}
					}
				});
				$(this).dialog('close');
			},
			'<{$lang.cancel}>' : function() {
				$(this).dialog('close');
			}
		}

	});

	// 弹出<{$lang.tip}>
	$("#alert_msg").dialog({
				autoOpen : false,
				modal : true,
				width : 600,
				show : "slide",
				buttons : {
					'<{$lang.close}>' : function() {
						$(this).dialog('close');
					}
				}

			});
	$(".checkAll").live("click", function() {
				if (typeof $(".checkAll").attr("checked") == "string") {
					$(".checkProduct").attr("checked", true);
				} else {
					$(".checkProduct").attr("checked", false);
				}

			});

});

function loadData(page, pageSize) {
	var billtype = $('[name=billtype]').val();
	var customer_id = $('[name=customer_id]').val();
	loading();
	$.ajax({ // 这里使用到Jquery的ajax<{$lang.method}>
		type : "POST",
		async : false,
		dataType : "json",
		url : "/plan/plan-usage-detail/list", // 请求的处理url
		data : {
			'page' : page, // 分页的页数
			'pageSize' : pageSize,
			'billtype' : billtype,
			'customer_id' : customer_id
		},
		success : function(json) {
			var list = '';
			if (json.ask != 1) {
				list += "<tr>";
				list = "<td colspan='12' class=''>&nbsp;<{$lang.no_data}></td>";
				list += "</tr>";
			} else {
				paginationTotal = json.count;
				$(".checkAll").attr("checked", false);
				$.each(json.result, function(key, val) {
					var cla = key % 2 == 0 ? "" : "even-tr";
					list += "<tr class='" + cla + "' id='product_"
							+ val.product_id + "'>";
//					list += "<td><input type='checkbox' value='"
//							+ val.product_id
//							+ "' class='checkProduct' name='checkPoduct[]'></td>";
					list += "<td>" + val.pud_id + "</td>";
					list += "<td>" + val.customer_id + "</td>";
					list += "<td>" + val.pu_id + "</td>";
					list += "<td>" + val.type + "</td>";
					list += "<td>" + val.ref_id + "</td>";
					list += "<td>" + val.count + "</td>";
					list += "<td>" + val.current_count + "</td>";
					list += "<td>" + val.created + "</td>";


					list += "</tr>";
				});
			}
//			alert(list);
			$("#list").html(list);
			closeLoading();
		}
	});
}

function search() {
	initData(0);
}


// <{$lang.delete}>
function delelteInfo(id) {
	if (id == '' || id == undefined) {
		return false;
	}
	Uid = id;
	$('#right_confirm').dialog('open');
}

function clear() {
	
}
